//
//  MediaEditTableViewCell.m
//  XPhoto
//
//  Created by baboy on 2019/5/5.
//  Copyright © 2019 baboy. All rights reserved.
//

#import "MediaEditTableViewCell.h"
@interface MediaEditTableViewCell()
@property(nonatomic, strong) IBOutlet UIView *rightViewContainer;
@end

@implementation MediaEditTableViewCell
- (void)dealloc{
    [self.leftImageView removeObserver:self forKeyPath:@"hidden"];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    [self.leftImageView addObserver:self forKeyPath:@"hidden" options:NSKeyValueObservingOptionNew context:nil];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
- (void)setLeftImageHidden:(BOOL)hidden{
//    self.leftImageView.hidden = hidden;
//    NSLayoutConstraint *leftConstraint = [self.contentView constraintForAttribute:NSLayoutAttributeLeading firstItem:self.titleLabel secondItem:self.leftImageView];
//    if (hidden) {
//        leftConstraint.constant = - self.leftImageView.bounds.size.width + 5;
//    }
//    if (!hidden) {
//        leftConstraint.constant = 5;
//    }
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
    if (object == self.leftImageView && [keyPath isEqualToString:@"hidden"]) {
        BOOL hidden = [[change valueForKey:NSKeyValueChangeNewKey] boolValue];
        NSLayoutConstraint *leftConstraint = [self.titleLabel.superview constraintForAttribute:NSLayoutAttributeLeading firstItem:self.titleLabel secondItem:self.leftImageView];
        if (hidden) {
            leftConstraint.constant = - self.leftImageView.bounds.size.width;
        }
        if (!hidden) {
            leftConstraint.constant = 5;
        }
        return;
    }
    [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
@end
